package com.daohang361.imqq.encoder;

import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.tool.ByteArray;
import com.daohang361.imqq.tool.Hex2Bytes;
import com.daohang361.imqq.tool.MyUtil;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-4-28 下午08:08:29 
 * 请求好友列表信息包	 
 * 协议格式:
 * 01 00 00 00 00 00 00 00 00 02${sequence}
 * sequence=page*4096
 */
public class Encoder0126 extends AbstractEncoder {

		@Override
		public byte[] encode(QQUser myqq, int command) {
			ByteArray myByte = doHead(myqq, "0126");
			myByte.saveThis();//保存此段作为第0段
			
			
			int firendInforCurrentPage=0;
			
			try {
				firendInforCurrentPage = MyUtil.byte2Int(myqq.getAttr("firendInforCurrentPage")[0]);//当前片段
				System.out.println("好友信息当前第"	+ firendInforCurrentPage + "页.");
			} catch (Exception e) {
				System.out.println("初始化第一次");
			}
			byte[] sequence = MyUtil.int2Bytes(firendInforCurrentPage*4096) ;
			myByte.putHex("01000000000000000002");
			myByte.putByte(sequence);
			firendInforCurrentPage++;
			//myByte.putInt(firendInforCurrentPage);
			myqq.addAttr("firendInforCurrentPage", MyUtil.int2Bytes(firendInforCurrentPage));
			myByte.saveThis();//保存此段作为第一段
			
			myByte.teaThis(1, 1,myqq.getAttr("SessionKey"));//加密第一段到第一段
			
			doTail(myByte);
			return myByte.getByteList();//返回完整的package
		}
		
		public static void main(String a[]){
			byte[] sequence = MyUtil.int2Bytes(1*4096) ;
			System.out.println(Hex2Bytes.bytesToHexString(sequence)
					);
		}
}
